スキップしてメイン コンテンツに移動

投稿

ラベル(CSV)が付いた投稿を表示しています

PHPでCSV形式でデータを出力するためのコード

PHPでCSVファイルを出力するためのコードサンプルです。 CsvWriterクラスが本体です。最低限のメソッドを定義してあるだけなので必要に応じて拡張してみてください。 Writerインタフェースを定義して、CsvWriterクラスのコンストラクタに渡して切り替えることで、出力方式を変更することができます。 CsvWriterクラス CSV形式で出力するための本体のクラスです。このクラスのコンストラクタにWriterインタフェースを実装したクラスを渡します。 <?php class CsvWriter { private Writer $writer; private $elements = []; public function __construct(Writer $writer) { $this->writer = $writer; } public function init() { $this->writer->init(); } public function appendValuesBySpecificOrder(array $values, $keys) { foreach ($keys as $key) { $this->appendEscaped($values[$key] ?? $default); } return $this; } public function appendValues(array $values) { foreach ($values as $value) { $this->appendEscaped($value); } return $this; } public function appendAsLine(array $values) { foreac...

Javascript Html 5 Canvas: Visualize CSV 2 Dimensional Data

Motivation: Visualize 2 Dimensional Data with Lightweight Way I wrote small java program for calculating Jaccard Similarity among source code in this post . And map into them 2 dimensional map using Multi Dimensional Scaling technique. I have used MDSJ – Multidimensional Scaling for Java . (By the way the library is quite simple and meet my requirement perfectly!! Excellent!!)> Next step is how to visualize the bunch of 2 dimensional (x,y) coordinate data so that human can easily understand. Of course, I am good at Java, I can write some code for visualize data in Java using Swing or Java FX etc. But it's not lightweight way. So, I decided to use HTML5 Canvas + Javascript. Viewer: Html5 Canvas + Javascript The features of the Data Viewer are: Visualize CSV data Expected 3 columns without header row: name...

Excel VBA: Output Sheet as UTF-8 CSV

Save Excel Sheet as UTF-8 CSV file The biggest problem of Excel is that Excel does not support saving file as UTF-8 CSV format. I have googled and tried to find the solution for saving excel as UTF-8 CSV but all of them requires 2 steps - 1) saving Excel file as Unicode csv 2) Open it by text editor and save it again as UTF-8 CSV. If you are a software developer, it is easy to write Java or C# program to manipulate Excel. But it means people (non developer users) need to install or launch the application. So I have wrriten Excel VBA addin for saving Excel sheet as UTF-8 CSV file so that we can save UTF-8 excel files only using Excel. Code for saving UTF-8 CSV Okie!, here is my solution! Sme notes for the code: The code saves an active sheet to UTF-8 CSV file in temp folder. The error handring part is not robust. I have only wrriten minimum error handling. You might need to add your custome error handring. If you are okay to add BOM on the file, please remove the corresp...