W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 2010-01-23 (토) 20:44:45 · 6907

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
16-07-13 조회 2,174
16-07-12 조회 2,361
16-07-12 조회 2,389
16-07-11 조회 2,196
16-06-05 조회 2,925
16-06-03 조회 3,052
16-05-26 조회 2,973
15-09-22 조회 4,995
15-06-10 조회 4,839
14-10-25 조회 6,373
14-10-22 조회 8,994
14-09-21 조회 5,796
14-09-16 조회 5,084
14-08-22 조회 1.1만
14-08-13 조회 5,925
14-08-12 조회 5,448
14-08-12 조회 6,309
14-08-11 조회 6,940
14-06-12 조회 6,222
14-06-11 조회 5,120
14-05-09 조회 5,444
14-05-09 조회 6,401
14-05-09 조회 6,430
14-05-08 조회 5,771
14-04-17 조회 4,774
14-04-16 조회 4,597
14-04-15 조회 4,597
14-04-15 조회 4,543
14-04-15 조회 4,316
14-04-14 조회 4,304
14-04-14 조회 4,273
14-04-14 조회 4,645
14-04-14 조회 4,786
14-04-14 조회 4,775
14-04-13 조회 4,678
14-04-12 조회 4,247
14-04-12 조회 4,386
14-04-12 조회 4,494
14-04-11 조회 5,016
14-04-10 조회 4,756
14-04-10 조회 4,794
14-04-09 조회 4,947
14-04-09 조회 5,317
14-04-08 조회 7,002
13-10-30 조회 7,665
13-07-11 조회 5,148
13-03-28 조회 1.1만
13-02-27 조회 6,798
13-02-14 조회 5,630
13-01-10 조회 4,526
12-12-31 조회 5,110
12-12-20 조회 6,128
12-12-12 조회 5,285
12-12-07 조회 4,518
12-11-28 조회 4,872
12-11-22 조회 5,310
12-11-12 조회 5,669
12-09-22 조회 4,524
12-09-18 조회 4,711